<template>
    <el-form :model="form" label-width="100px" class="form-container" label-position="right">
        <!-- 双人资料 -->
        <el-row :gutter="20">
            <el-col :span="12">
                <h3 class="section-title">逝者一</h3>
                <el-form-item label="姓名" required>
                    <el-input v-model="form.deceased1.name" />
                </el-form-item>
                <el-form-item label="出生日期" required>
                    <el-date-picker v-model="form.deceased1.birth" type="date" />
                </el-form-item>
                <el-form-item label="过世日期" required>
                    <el-date-picker v-model="form.deceased1.death" type="date" />
                </el-form-item>
                <el-form-item label="国籍">
                    <el-input v-model="form.deceased1.nationality" />
                </el-form-item>
                <el-form-item label="祖籍">
                    <el-input v-model="form.deceased1.ancestral" />
                </el-form-item>
                <el-form-item label="宗教">
                    <el-input v-model="form.deceased1.religion" />
                </el-form-item>
                <el-form-item label="职业">
                    <el-input v-model="form.deceased1.job" />
                </el-form-item>
                <el-form-item label="职业">
                    <el-input v-model="form.deceased1.job" />
                </el-form-item>
                <el-form-item label="情感关系" prop="relationship">
                    <template #default>
                        <div class="w-[280px]">
                            <el-select v-model="form.deceased1.relationship" clearable placeholder="请选择情感关系" style="width: 100%;">
                                <el-option v-for="item in relationshipList" :key="item.value" :label="item.label"
                                    :value="item.value" />
                            </el-select>
                        </div>
                    </template>
                </el-form-item>
                <el-form-item label="单人照">
                    <el-upload :auto-upload="false" :show-file-list="true" :on-change="handleChange1">
                        <el-button>上传照片</el-button>
                    </el-upload>
                </el-form-item>
            </el-col>

            <el-col :span="12">
                <h3 class="section-title">逝者二</h3>
                <el-form-item label="姓名" required>
                    <el-input v-model="form.deceased2.name" />
                </el-form-item>
                <el-form-item label="出生日期" required>
                    <el-date-picker v-model="form.deceased2.birth" type="date" />
                </el-form-item>
                <el-form-item label="过世日期" required>
                    <el-date-picker v-model="form.deceased2.death" type="date" />
                </el-form-item>
                <el-form-item label="国籍">
                    <el-input v-model="form.deceased2.nationality" />
                </el-form-item>
                <el-form-item label="祖籍">
                    <el-input v-model="form.deceased2.ancestral" />
                </el-form-item>
                <el-form-item label="宗教">
                    <el-input v-model="form.deceased2.religion" />
                </el-form-item>
                <el-form-item label="职业">
                    <el-input v-model="form.deceased2.job" />
                </el-form-item>
                <el-form-item label="情感关系" prop="relationship2">
                    <template #default>
                        <div class="w-[280px]">
                            <el-select v-model="form.deceased2.relationship2" clearable placeholder="请选择情感关系" style="width: 100%;">
                                <el-option v-for="item in relationshipList" :key="item.value" :label="item.label"
                                    :value="item.value" />
                            </el-select>
                        </div>
                    </template>
                </el-form-item>
                <el-form-item label="单人照">
                    <el-upload :auto-upload="false" :show-file-list="true" :on-change="handleChange2">
                        <el-button>上传照片</el-button>
                    </el-upload>
                </el-form-item>
            </el-col>
        </el-row>

        <!-- 合照 -->
        <el-divider>合照上传</el-divider>
        <el-form-item label="合照">
            <el-upload :auto-upload="false" :show-file-list="true" :on-change="handleGroupChange">
                <el-button>上传合照</el-button>
            </el-upload>
        </el-form-item>

        <!-- 墓碑信息 -->
        <el-form-item label="墓碑显示">
            <el-radio-group v-model="form.tombstoneType">
                <el-radio label="单人照" />
                <el-radio label="合照" />
            </el-radio-group>
        </el-form-item>

        <el-form-item label="纪念馆别名">
            <el-input v-model="form.nickname" placeholder="如：慈父某某的天堂家园" />
        </el-form-item>

        <el-form-item label="墓碑寄语" required>
            <el-input type="textarea" v-model="form.motto" :rows="3" />
        </el-form-item>

        <el-form-item label="生平简介" required>
            <el-input type="textarea" v-model="form.bio" :rows="5" />
        </el-form-item>

        <el-form-item label="建立人署名">
            <el-input v-model="form.createdBy" />
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="submit">提交信息</el-button>
        </el-form-item>
    </el-form>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { apiMyMuEdit, apiMyMuDetail, apiMyMuRelation } from '@/api/graveyard'
const props = defineProps({
    memorialId: {
        type: String,
        default: ''
    }
})
const form = ref({
    deceased1: {
        name: '',
        birth: '',
        death: '',
        nationality: '中国',
        ancestral: '',
        religion: '',
        job: '',
        relationship: '',
    },
    deceased2: {
        name: '',
        birth: '',
        death: '',
        nationality: '中国',
        ancestral: '',
        religion: '',
        job: '',
        relationship2: '',
    },
    tombstoneType: '单人照',
    nickname: '',
    motto: '',
    bio: '',
    createdBy: '',
})

const relationshipList = ref([])

const handleChange1 = (file: any) => {
    console.log('逝者一上传：', file)
}
const handleChange2 = (file: any) => {
    console.log('逝者二上传：', file)
}
const handleGroupChange = (file: any) => {
    console.log('合照上传：', file)
}

const submit = () => {
    console.log('提交：', form.value)
}


// 获取情感关系
const getRelationshipList = async () => {
    const data = await apiMyMuRelation({page_no: 1, page_size: 9999})
    relationshipList.value = data
}

onMounted(() => {
    getRelationshipList()
})
</script>

<style scoped>
.form-container {
    max-width: 1200px;
    margin: 30px auto;
    padding: 30px;
    border: 1px solid #e0e0e0;
    background-color: #fff;
    border-radius: 8px;
}

.section-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 10px;
}
</style>